package fifteenth.取得类的结构;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

public class 取得类的属性 {
    public static void main(String[] args) throws ClassNotFoundException {
        Class<?> c = Class.forName("fifteenth.取得类的结构.Person");
        Field[] df = c.getDeclaredFields();
        for (int i = 0; i < df.length; i++) {
            int modifiers = df[i].getModifiers();// 获取修饰符数字
            String modifier = Modifier.toString(modifiers);
            Class<?> type = df[i].getType();// 取得属性的类型
            System.out.print("本类修饰符：");
            System.out.print(modifier + " ");
            System.out.print(type.getName() + " ");// 输出属性类型 比如String
            System.out.print(df[i].getName());// 输出属性名称 比如name
            System.out.println(";");
        }
        System.out.println("--------------------------------");
        {
            Field[]  f= c.getFields();
            for (int i = 0; i < f.length; i++) {//取得公共父类属性
                int modifiers = f[i].getModifiers();
                String m= Modifier.toString(modifiers);
                Class<?> type = f[i].getType();//获取属性类型
                System.out.print("公共属性：");
                System.out.print(m+" ");
                System.out.print(type.getName()+" ");
                System.out.print(f[i].getName());//获取属性名称
                System.out.println(";");
            }
        }

    }
}
/*
D:\WorkSpaces\Java\jdk-21\bin\java.exe "-javaagent:D:\Software\IntelliJ IDEA\IntelliJ IDEA 2023.3.2\lib\idea_rt.jar=51455:D:\Software\IntelliJ IDEA\IntelliJ IDEA 2023.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath D:\WorkSpaces\JavaDevelopBase_start_329\out\production\JavaDevelopBase_start_329 fifteenth.取得类的结构.取得类的属性
本类修饰符：private java.lang.String name;
本类修饰符：private int age;
--------------------------------
公共属性：public static final java.lang.String NATIONAL;
公共属性：public static final java.lang.String STUDENT;

Process finished with exit code 0

 */